feat(flexible-outcalls): handle flexible errors#9709
Merged
Conversation
4daca11 to
aab90a1
Compare
maksymar
approved these changes
Apr 8, 2026
eichhorl
reviewed
Apr 8, 2026
eichhorl
reviewed
Apr 8, 2026
eichhorl
reviewed
Apr 10, 2026
eichhorl
reviewed
Apr 10, 2026
eichhorl
approved these changes
Apr 13, 2026
daniel-wong-dfinity-org
pushed a commit
that referenced
this pull request
Apr 15, 2026
## Summary Adds error-path support for flexible HTTP outcalls in the consensus payload. Previously, only the success path (`FlexibleCanisterHttpResponses`) was handled. This PR introduces a new `flexible_errors` field on `CanisterHttpPayload` to carry three error types through consensus: - **`Timeout`**: The request exceeded `CANISTER_HTTP_TIMEOUT_INTERVAL`. Flexible timeouts are now reported via `flexible_errors` (instead of the regular `timeouts` vec) so they can later be encoded as `FlexibleHttpRequestResult::Err` with a `global_error`, enabling programmatic detection. For now, flexible timeouts do not carry information, however, the type is designed so that it could carry more information in the future (e.g., it could contain all rejects/error responses). - **`TooManyRequestErrors`**: More HTTP adapter nodes returned reject responses than the slack allows (`committee.len() - min_responses`), meaning `min_responses` OK responses can never be reached. Carries the reject response+proof pairs for validation. - **`ResponsesTooLarge`**: Even the smallest `min_responses` OK responses (by `content_size`) exceed `MAX_CANISTER_HTTP_PAYLOAD_SIZE` when summed. Carries the metadata shares as proof. The validation logic still has a bug, which will be fixed in CON-1709. This addresses CON-1691, CON-1692, and CON-1693. ### Key changes - **`find_flexible_result` replaces `find_flexible_responses`** (`utils.rs`): A single scan now sorts shares by `content_size` ascending (favoring smaller responses), collects OK and reject responses, and returns one of `OkResponses`, `Error(TooManyRequestErrors | ResponsesTooLarge)`, or `Pending`. - **Payload building**: The main loop integrates `find_flexible_result` and routes flexible timeouts to `flexible_errors` instead of `timeouts`. - **Payload validation**: A new validation block for `flexible_errors` checks: - Timeout: request is actually expired. - TooManyRequestErrors: entries are rejects, from unique committee members with valid signatures, and the reject count exceeds the allowed slack. - ResponsesTooLarge: shares are from unique committee members with valid signatures, and the smallest `min_responses` entry sizes truly exceed the payload limit. - **Validation refactoring** (`utils.rs`): Common per-entry and per-share validation logic is extracted into `validate_flexible_response_with_proof` and `validate_response_share`, eliminating duplication between OK-response and error-response validation. - **`CountBytes` precision fix** (`canister_http.rs`): `CanisterHttpResponseMetadata::count_bytes()` now uses precise field-by-field calculation instead of `size_of::<Self>()`, which was incorrect for heap-allocated fields like `CryptoHash` and `ReplicaVersion`. ### Not included `into_messages` conversion of `flexible_errors` into Candid-encoded `FlexibleHttpRequestResult::Err` will be done in a follow-up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds error-path support for flexible HTTP outcalls in the consensus payload. Previously, only the success path (
FlexibleCanisterHttpResponses) was handled. This PR introduces a newflexible_errorsfield onCanisterHttpPayloadto carry three error types through consensus:Timeout: The request exceededCANISTER_HTTP_TIMEOUT_INTERVAL. Flexible timeouts are now reported viaflexible_errors(instead of the regulartimeoutsvec) so they can later be encoded asFlexibleHttpRequestResult::Errwith aglobal_error, enabling programmatic detection. For now, flexible timeouts do not carry information, however, the type is designed so that it could carry more information in the future (e.g., it could contain all rejects/error responses).TooManyRequestErrors: More HTTP adapter nodes returned reject responses than the slack allows (committee.len() - min_responses), meaningmin_responsesOK responses can never be reached. Carries the reject response+proof pairs for validation.ResponsesTooLarge: Even the smallestmin_responsesOK responses (bycontent_size) exceedMAX_CANISTER_HTTP_PAYLOAD_SIZEwhen summed. Carries the metadata shares as proof. The validation logic still has a bug, which will be fixed in CON-1709.This addresses CON-1691, CON-1692, and CON-1693.
Key changes
find_flexible_resultreplacesfind_flexible_responses(utils.rs): A single scan now sorts shares bycontent_sizeascending (favoring smaller responses), collects OK and reject responses, and returns one ofOkResponses,Error(TooManyRequestErrors | ResponsesTooLarge), orPending.Payload building: The main loop integrates
find_flexible_resultand routes flexible timeouts toflexible_errorsinstead oftimeouts.Payload validation: A new validation block for
flexible_errorschecks:min_responsesentry sizes truly exceed the payload limit.Validation refactoring (
utils.rs): Common per-entry and per-share validation logic is extracted intovalidate_flexible_response_with_proofandvalidate_response_share, eliminating duplication between OK-response and error-response validation.CountBytesprecision fix (canister_http.rs):CanisterHttpResponseMetadata::count_bytes()now uses precise field-by-field calculation instead ofsize_of::<Self>(), which was incorrect for heap-allocated fields likeCryptoHashandReplicaVersion.Not included
into_messagesconversion offlexible_errorsinto Candid-encodedFlexibleHttpRequestResult::Errwill be done in a follow-up.